#include <cstdio>
#include <cstdlib>
typedef struct{
    char name[11];
    char stnum[11];
    int score;
}info_t,*pinfo_t;
int main()
{
    int num;
    scanf("%d",&num);
    int min=101,max=-1,mini,maxi;//分别记录最低最高成绩拥有者的结构体数组下标
    pinfo_t sinfo;
    sinfo=(pinfo_t)calloc(num,sizeof(info_t));
    int i;
    for(i=0;i<num;++i)
    {//读取数据的同时记录最高分与最低分
        //getchar();
        scanf("%s%s%d",(sinfo+i)->name,(sinfo+i)->stnum,&(sinfo+i)->score);
        if((sinfo+i)->score>max)
        {
            max=(sinfo+i)->score;
            maxi=i;
        }
        if((sinfo+i)->score<min)
        {
            min=(sinfo+i)->score;
            mini=i;
        }
    }
    printf("%s %s\n",(sinfo+maxi)->name,(sinfo+maxi)->stnum);
    printf("%s %s\n",(sinfo+mini)->name,(sinfo+mini)->stnum);
}
